def count_ways(s):
    n = len(s)
    MOD = 10**9 + 7
    dp = [[[0] * 3 for _ in range(n + 1)] for _ in range(n + 1)]
    
    # Base case: empty string
    dp[0][0][0] = 1  # assuming '0' means neutral element for multiplication table (not used here)
    
    for i in range(1, n + 1):
        for j in range(i + 1):
            for k in range(3):
                if j == 0:  # No parentheses
                    dp[i][j][k] = 0
                else:
                    for p in range(j):
                        for l in range(3):
                            if s[i-1] == 'a':
                                if (l == 0 and k == 1) or (l == 1 and k == 0):
                                    dp[i][j][k] = (dp[i][j][k] + dp[i-1][p][l]) % MOD
                            elif s[i-1] == 'b':
                                if (l == 0 and k == 2) or (l == 2 and k == 0):
                                    dp[i][j][k] = (dp[i][j][k] + dp[i-1][p][l]) % MOD
                            elif s[i-1] == 'c':
                                if (l == 1 and k == 2) or (l == 2 and k == 1):
                                    dp[i][j][k] = (dp[i][j][k] + dp[i-1][p][l]) % MOD
    
    # Summing up all ways to get the result '0' (which is neutral in this problem, as we are checking value 'a')
    total_ways = sum(dp[n][i][0] for i in range(n + 1)) % MOD
    
    return total_ways

if __name__ == "__main__":
    with open('input.txt', 'r') as file:
        s = file.readline().strip()
    
    result = count_ways(s)
    with open('output.txt', 'w') as file:
        file.write(str(result))
